package com.restaurant.order;
import java.util.Objects;
abstract class Dish {
    private String name;
    private String description;
    private double price;
    private int stock;
    private boolean isOnSale;
    public Dish(String name, String description, double price, int stock) {
        this.name = name;
        this.description = description;
        this.price = price;
        this.stock = stock;
        this.isOnSale = true;
    }
    public String getName() { return name; }
    public double getPrice() { return price; }
    public int getStock() { return stock; }
    public boolean isOnSale() { return isOnSale; }
    public void reduceStock(int quantity) throws Exception {
        if (quantity <= 0) {
            throw new Exception("购买数量不能小于等于0");
        }
        if (this.stock < quantity) {
            throw new Exception("菜品【" + name + "】库存不足，当前库存：" + stock);
        }
        this.stock -= quantity;
    }
    public void takeOffSale() { this.isOnSale = false; }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dish dish = (Dish) o;
        return Objects.equals(name, dish.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
class StapleFood extends Dish {
    private String taste;

    public StapleFood(String name, String description, double price, int stock, String taste) {
        super(name, description, price, stock);
        this.taste = taste;
    }

    public String getTaste() { return taste; }
}
class Beverage extends Dish {
    private boolean isCold;

    public Beverage(String name, String description, double price, int stock, boolean isCold) {
        super(name, description, price, stock);
        this.isCold = isCold;
    }

    public boolean isCold() { return isCold; }
}